##
 # Copyright 2009 Caio Souza
 # This file is part of Rpyg.
 #
 # Rpyg is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # Rpyg is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with Rpyg. If not, see <http://www.gnu.org/licenses/>.
 ##

from rpyg import *

import pygame
from pygame.locals import *

def getCharImages(file, time):
    south = []
    for pos in [(32, 0), (0, 0), (32, 0), (64, 0)]:
        pos += (32, 48)
        south.append(Frame(Layer(file, pos), time))
    south = Image(south)

    west = []
    for pos in [(32, 48), (0, 48), (32, 48), (64, 48)]:
        pos += (32, 48)
        west.append(Frame(Layer(file, pos), time))
    west = Image(west)

    east = []
    for pos in [(32, 96), (0, 96), (32, 96), (64, 96)]:
        pos += (32, 48)
        east.append(Frame(Layer(file, pos), time))
    east = Image (east)

    north = []
    for pos in [(32, 144), (0, 144), (32, 144), (64, 144)]:
        pos += (32, 48)
        north.append(Frame(Layer(file, pos), time))
    north = Image(north)

    return {'north': north, 'south': south, 'east': east, 'west': west}

images = getCharImages(('data', 'images', 'hero.png'), 250)
joystick = Joystick(east = K_d, north = K_w, south = K_s, west = K_a, act = K_SPACE)
hero = Character(images, joystick, (7, 7), (0, -16))

images = getCharImages(('data', 'images', 'lady.png'), 300)
joystick = Automatic(['e', 'e', 'e', 's', 'e', 'e', 'e', 'e', 'e', 's', 's', 's', 's', 's', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'n', 'n', 'n', 'n', 'n', 'n', 'e'])
lady = Character(images, joystick, (17, 7), (0, -16), KEY_EAST, 16, 100)

images = getCharImages(('data', 'images', 'sheep.png'), 400)
joystick = Automatic([])
sheep = Character(images, joystick, (10, 10), (0, -16), KEY_EAST, 16, 40)
sheep.addEvent (AddMove(ACT_FROM_NORTH, joystick, [State(MOVE_KEY, 0, key = KEY_SOUTH)]))
sheep.addEvent (AddMove(ACT_FROM_SOUTH, joystick, [State(MOVE_KEY, 0, key = KEY_NORTH)]))
sheep.addEvent (AddMove(ACT_FROM_EAST, joystick, [State(MOVE_KEY, 0, key = KEY_WEST)]))
sheep.addEvent (AddMove(ACT_FROM_WEST, joystick, [State(MOVE_KEY, 0, key = KEY_EAST)]))
